
source ~/.bash_profile
source /etc/profile

IPANAME="QFTEST"
SCHEME="QFTEST"
COMPILE="Release"

if [ ${VERSION} = "Master" ] || [ ${VERSION} = "TEST" ] || [ ${VERSION} = "Developer" ] || [ ${VERSION} = "Bug_Fix" ] || [ ${VERSION} = "Refactor_mater" ]
then
    echo "这个分支是Master"
    echo ${VERSION}
    echo ${ENV}
    
    IPANAME="QFBAPP"
    SCHEME="QFBAPP"
    
    if [ ${ENV} = "DEV" ]
    then
        COMPILE="Debug"
    elif [ ${ENV} = "TEST" ]
    then
        COMPILE="TEST"
    else
        COMPILE="Release"
    fi
    
elif [ ${VERSION} = "customMaster/BangFangMaster" ]
then
    echo "BangFangMaster"
    IPANAME="ReleaseBangFang"
    SCHEME="ReleaseBangFang"
    
    if [ ${ENV} = "DEV" ]
    then
        COMPILE="DebugBangFang"
    elif [ ${ENV} = "TEST" ]
    then
        COMPILE="TESTBangFang"
    else
        COMPILE="ReleaseBangFang"
    fi
    
    
elif [ ${VERSION} = "customMaster/KeweiMaster" ]
then
    echo "KeweiMaster"
    IPANAME="KeweiAPP"
    SCHEME="KeweiAPP"
    
    if [ ${ENV} = "DEV" ]
    then
        COMPILE="KeweiAPP"
    elif [ ${ENV} = "TEST" ]
    then
        COMPILE="KeweiAPP"
    else
        COMPILE="KeweiAPP"
    fi
    
    
elif [ ${VERSION} = "customMaster/OneRoomMaster" ]
then
    echo "OneRoomMaster"
    IPANAME="OneRoomApp"
    SCHEME="OneRoomApp"
    
    
    if [ ${ENV} = "DEV" ]
    then
        COMPILE="DebugOneRoom"
    elif [ ${ENV} = "TEST" ]
    then
        COMPILE="TESTOneRoom"
    else
        COMPILE="OneRoomApp"
    fi
    
    
elif [ ${VERSION} = "customMaster/ZhongYouMaster" ]
then
    echo "ZhongYouMaster"
    
    IPANAME="ZhongYouApp"
    SCHEME="ZhongYouApp"
    
    if [ ${ENV} = "DEV" ]
    then
        COMPILE="DebugZhongYou"
    elif [ ${ENV} = "TEST" ]
    then
        COMPILE="TESTZhongYou"
    else
        COMPILE="ZhongYouApp"
    fi
elif [ ${VERSION} = "customMaster/HengXinMaster" ]
then
    echo "HengXinMaster"
    IPANAME="HengXinAPP"
    SCHEME="HengXinAPP"
    COMPILE="HengXinApp"
elif [ ${VERSION} = "customMaster/NewRongChuangMaster" ]
then
    echo "HengXinMaster"
    IPANAME="RongchuangAPP"
    SCHEME="RongchuangAPP"
    COMPILE="RongchuangAPP"
elif [ ${VERSION} = "branch/xflcMaster" ]
then
    echo "xflcMaster"
    IPANAME="XFLCApp"
    SCHEME="XFLCApp"
    COMPILE="XFLCApp"
else
    echo "Master"
    IPANAME="QFBAPP"
    SCHEME="QFBAPP"
fi

export FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT=120

fastlane gym --export_method enterprise --workspace QFBAPP.xcworkspace --output_name ${IPANAME} --scheme ${SCHEME} --configuration ${COMPILE} --export_xcargs -allowProvisioningUpdates
MSG=`git log -1 --pretty=%B`
INFO=`curl -F "file=@${IPANAME}.ipa" -F "uKey=c68d1ed44f9695ec34372b2b287e2a20" -F "_api_key=7103ad5f876f429e87521fb095d2f5cf" -F "updateDescription=${MSG}" https://qiniu-storage.pgyer.com/apiv1/app/upload`
echo ${INFO}

INFO=$(echo ${INFO})

#dingding
DINGDING_ROBOT_URL="https://oapi.dingtalk.com/robot/send?access_token=68d9d327cb3d71ccd6ae0bf720e2d00fd730efc587d9756df41ce7968d21ca34"



DINGDING_appQRCodeURL=$(echo $(echo ${INFO} |jq '.data.appQRCodeURL') | sed 's/\"//g')
DINGDING_appUpdateDescription=$(echo $(echo ${INFO} |jq '.data.appUpdateDescription') | sed 's/\"//g')
DINGDING_appBuildVersion=$(echo $(echo ${INFO} |jq '.data.appBuildVersion') | sed 's/\"//g')
DINGDING_appVersion=$(echo $(echo ${INFO} |jq '.data.appVersion') | sed 's/\"//g')
DINGDING_appIdentifier=$(echo $(echo ${INFO} |jq '.data.appIdentifier') | sed 's/\"//g')
DINGDING_appName=$(echo $(echo ${INFO} |jq '.data.appName') | sed 's/\"//g')


DINGDING_TEXT="# iOS \n \n ![alt](${DINGDING_appQRCodeURL})  \n \n 分支 : ${VERSION} \n\n 环境 : ${ENV} \n \n Bundle ID : ${DINGDING_appIdentifier} \n \n 包名 : ${DINGDING_appName} \n \n 版本号 : ${DINGDING_appVersion} \n \n 蒲公英buildVersion : ${DINGDING_appBuildVersion} \n \n 最后提交信息 : ${DINGDING_appUpdateDescription} \n \n [点击在线安装](https://www.pgyer.com/1oYh) \n \n [扫码或点击查看所有app:](https://www.pgyer.com/qiaofang) \n \n ![alt](https://www.pgyer.com/group/qrcode/58bc34eed6b8ed814d0afc0befa3ede9)"

DINGDINGMSG='{"msgtype": "markdown",
"markdown": {
"title":"iOS测试",
"text":"'${DINGDING_TEXT}'"
}
}'


#echo ${DINGDINGMSG}

#echo ${DINGDINGMSG} |jq '.'

if [ "${NOTIFICATION}" = true ]
then
    curl 'https://oapi.dingtalk.com/robot/send?access_token=68d9d327cb3d71ccd6ae0bf720e2d00fd730efc587d9756df41ce7968d21ca34' \
-H 'Content-Type: application/json' \
-d "$(echo $DINGDINGMSG)"
fi




